<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>react状态提升</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
  <!-- 使用jsx需要babel转义 -->
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <!-- 使用babel需要申明type -->
  <script type="text/babel">
    // ***我自己的封装***
    // function ReactEl(data) {
    //   let tag = document.querySelector(data.el)
    //   return tag
    // }
    // ReactDOM.render(
    //   <h1>hello，reactyyy</h1>,
    //   new ReactEl({
    //     el: '#app'
    //   })
    // )
    // 山地人的封装
    function createApp({el='#app',comp}) {
      ReactDOM.render(comp,document.querySelector(el))
    }

    class Add extends React.Component{
      constructor(props) {
        super(props)
        this.kk = this.kk.bind(this)
      }
      kk(event) {
        console.log('kkkk---->')
        this.props.onChange(event)
      }
      render() {
        const { count } = this.props
        return (
          <h1>add
              <input value={count / 10} onChange={this.kk}/>  
          </h1>
        )
      }
    }



    class Scp extends React.Component{
      constructor(props) {
        super(props)
        this.state = {
          count: 50
        }
        this.hander = this.hander.bind(this)
        this.pp = this.pp.bind(this)
      }
      hander(event) {
        console.log('hander---->')
        this.setState({
          count: event.target.value
        })
      }
      pp(e) {
        console.log(this.state.count)
        e.preventDefault()

        alert('hander---->'+this.state.count)

      }
      render() {
        const { count } = this.state
        return (
          <div>hhhh
            <form onSubmit={this.pp}>
              <input value={count} onChange={this.hander}/>  
              <Add onChange={this.hander} count={count}/>
              <input type='submit' value='提交' />
            </form>
          </div>
        )
      }
    }



    createApp({
      // el:'#root',
      comp: <Scp />,
    })
  </script>
</body>
</html>